package com.work.farm.controller;

import com.work.entity.Result;
import com.work.entity.StatusCode;
import com.work.farm.pojo.TCustFarmlandCropsEntity;
import com.work.farm.service.FarmLandCropsService;
import org.omg.CORBA.INTERNAL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/farmCrops")
public class FarmLandCropsController {

    @Autowired
    private FarmLandCropsService farmCropsService;

    /**
     * 种植农作物
     */
    @PostMapping("/addFarmCrops")
    public Result addFarmCrops(@RequestBody TCustFarmlandCropsEntity tCustFarmlandCropsEntity){

        try{
            farmCropsService.addFarmCrops(tCustFarmlandCropsEntity);
            return new Result(true, StatusCode.ADD_OK,"添加成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, StatusCode.ADD_ERROR,"添加失败");
        }
    }

    /*
    农作物详情
     */
    @GetMapping("/findById")
    public Result findById(@RequestParam("fid")Integer fid){
        try{
            Map map = farmCropsService.findById(fid);
            return new Result(true,StatusCode.FIND_Ok,"查询成功",map);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,StatusCode.FIND_ERROR,"查询失败");
        }
    }

    @PutMapping("/updateStatus")
    public Result updateStatus(Integer fid,String stage){
        try{
            farmCropsService.updateStatus(fid,stage);
            return new Result(true,StatusCode.UPDATE_Ok,"修改成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,StatusCode.UPDATE_ERROR,"修改失败");
        }
    }

}
